package br.com.webcrm.view;

import java.util.List;

import br.com.webcrm.model.Telefone;

@SuppressWarnings("serial")
public class TelefoneDataModel extends PrimeDataModel<Telefone> {

    public TelefoneDataModel() {
    }

    public TelefoneDataModel(Object data) {
        super(data);
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public Telefone getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        List<Telefone> telefones = (List<Telefone>) getWrappedData();
        
        for(Telefone telefone : telefones) {
        	String id = ""+telefone.getIdTelefone();
            if(id.equals(rowKey))
                return telefone;
        }
        
        return null;
    }

    @Override
    public String getRowKey(Telefone telefone) {
        return ""+telefone.getIdTelefone();
    }
}
                    
